//
//  ListViewController.m
//  SegmentDemo
//
//  Created by 塔兮 on 2022/4/11.
//

#import "ListViewController.h"

@interface ListViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) NSArray *list;
@property (nonatomic, strong) UITableView *tableView;

@end

@implementation ListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self configureData];
    [self configureView];
}

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCWidth, SCHeight - NavBarAndStatusBarHeight) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.estimatedRowHeight = 40;
        _tableView.backgroundColor = UIColorFromHex(@"FFFFFF");
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_tableView registerClass:[ListTableViewCell class] forCellReuseIdentifier:@"ListTableViewCell"];
    }
    return _tableView;
}

- (void)configureView {
    self.title = @"分页";
    [self.view addSubview:self.tableView];
}

- (void)configureData {
    self.list = @[@"卡片",@"文字",@"带下划线文字",@"带背景色文字",@"图片",@"图片文字（图片居左）",@"图片文字（图片居上）"];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.list.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ListTableViewCell"];
    if (!cell) {
        cell = [[ListTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ListTableViewCell"];
    }
    cell.stringName = self.list[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        CardViewController *card = [CardViewController new];
        [self.navigationController pushViewController:card animated:YES];
    }
    
    if (indexPath.row == 1) {
        TextViewController *text = [TextViewController new];
        [self.navigationController pushViewController:text animated:YES];
    }
    
    if (indexPath.row == 2) {
        BottomLineTextViewController *text = [BottomLineTextViewController new];
        [self.navigationController pushViewController:text animated:YES];
    }
    
    if (indexPath.row == 3) {
        BackTextViewController *backText = [BackTextViewController new];
        [self.navigationController pushViewController:backText animated:YES];
    }
    
    if (indexPath.row == 4) {
        ImageViewController *image = [ImageViewController new];
        [self.navigationController pushViewController:image animated:YES];
    }
    
    if (indexPath.row == 5) {
        LeftImageViewController *leftImage = [LeftImageViewController new];
        [self.navigationController pushViewController:leftImage animated:YES];
    }
    
    if (indexPath.row == 6) {
        TopImageViewController *topImage = [TopImageViewController new];
        [self.navigationController pushViewController:topImage animated:YES];
    }
}

@end
